package com.aier.admin_new.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.ClassParent;
import com.aier.classes.entity.ClassTeacher;
import com.aier.classes.service.IClassUserService;
import com.aier.common.common.CommonSession;
import com.aier.school.entity.SchoolTeacher;
import com.aier.school.service.ISchoolTeacherService;
@Scope("prototype")
@Component("userStautsAction")
public class UserStautsAction extends AdminNewBaseAction {

	private static final long serialVersionUID = 1L;
	
	private int  sid;//学校ID
	private long cid;//班级ID
	private long uid;//用户ID
	private long tid;//教师ID
	private int s; // 成功:1 ,失败:0
	private String error_info; // 错误提示信息
	
	@Resource(name = "schoolTeacherService")
	private ISchoolTeacherService schoolTeacherService;
	@Resource(name = "classUserService")
	private IClassUserService classUserService;
	
	private String appStatus;// APP登录时候的身份 1 校长级别的管理员 ，2 班级管理员 3 普通老师 4 家长   5未确定身份的用户
	
	
	public String checkStauts(){
		appStatus ="";
		SchoolTeacher schoolTeacher = schoolTeacherService.searchSchoolTeacherByIds(uid, sid);
		ClassTeacher classTeacher = classUserService.searchClassTeacherByIds(uid, cid);
		List<ClassParent> classParentList = classUserService.searchClassParentListByUid(uid);
		tid=schoolTeacher.getTid();
		if (schoolTeacher != null && (schoolTeacher.getIsadmin() == (short) 1)) { // 学校管理员
				appStatus +="1,";										
		} 
		if (classTeacher != null && (classTeacher.getIsadmin() == (short) 1)) {// 班级管理员
				appStatus +="2,";//
		}
		if(classTeacher != null && (classTeacher.getIsadmin() == (short) 0 )&& (schoolTeacher.getIsadmin() == (short) 0)){//老师
				appStatus +="3,";//老师
		}		
		if (classParentList.size()>0) {			
			appStatus +="4,";	//家长
		}
		
		s = 1;
		return SUCCESS;
	}
	
		
	public int getS() {
		return s;
	}
	public String getError_info() {
		return error_info;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public void setCid(long cid) {
		this.cid = cid;
	}
	public void setUid(long uid) {
		this.uid = uid;
	}
	
	public long getTid() {
		return tid;
	}

	public String getAppStatus() {
		return appStatus;
	}

	public void setSchoolTeacherService(ISchoolTeacherService schoolTeacherService) {
		this.schoolTeacherService = schoolTeacherService;
	}
	
	public void setClassUserService(IClassUserService classUserService) {
		this.classUserService = classUserService;
	}
}